﻿CREATE PROCEDURE [ProductFeedback].[GetProductFeedbackBadgeProductRelations]
	@TenantId uniqueidentifier,
	@CatalogId [ProductFeedback].[TCatalogId],
	@ProductId [ProductFeedback].[TProductId]
AS

-- 1st
SELECT
	PFBPA.BadgeId,
	PFBPA.StartDate,
	PFBPA.FinishDate,
	PFBPA.DisplayOrder
FROM
	ProductFeedbackBadgeProductAssociation PFBPA
	INNER JOIN ProductFeedbackBadge PFB ON PFBPA.TenantId = PFB.TenantId AND PFBPA.BadgeId = PFB.BadgeId
WHERE
	PFBPA.CatalogId = @CatalogId
	AND PFBPA.ProductId = @ProductId
	AND PFB.TenantId = @TenantId

-- 2nd
SELECT
	PFBPD.BadgeId,
	PFBPD.StartDate,
	PFBPD.FinishDate
FROM
	ProductFeedbackBadgeProductDisassociation PFBPD
	INNER JOIN ProductFeedbackBadge PFB ON PFBPD.TenantId = PFB.TenantId AND PFBPD.BadgeId = PFB.BadgeId
WHERE
	PFBPD.CatalogId = @CatalogId
	AND PFBPD.ProductId = @ProductId
	AND PFB.TenantId = @TenantId
